package com.axjy.web;

import com.axjy.pojo.User;
import com.axjy.service.UserService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * Created by zjn on 2018/2/6.
 */
@Controller
@RequestMapping("/login")
public class LoginHandler {

    @Resource
    private UserService userService;


    @PostMapping("/check")
    public String login(String name, String password, Model model, HttpSession session){
        User user=userService.check(name,password);
        if(user==null){
            model.addAttribute("loginErr","用户名或密码错误");
            return "forward:/login.jsp";
        }
        session.setAttribute("user",user);
        return "redirect:/index";
    }

}
